<?php
    // +----------------------------------------------------------------------
    // | Created by PHPstorm: JRKAdmin框架 [ JRKAdmin ] 
    // +----------------------------------------------------------------------
    // | Copyright (c) 2019~2022 [LuckyHHY] All rights reserved.
    // +----------------------------------------------------------------------
    // | SiteUrl: http://www.luckyhhy.cn
    // +----------------------------------------------------------------------
    // | Author: LuckyHhy <jackhhy520@qq.com>
    // +----------------------------------------------------------------------
    // | Date: 2020/3/26-11:37
    // +----------------------------------------------------------------------
    // | Description:  
    // +----------------------------------------------------------------------


    namespace app\admin\controller\push;


    use app\admin\controller\AdminBase;
    use app\admin\library\Push;

    class Xzhang extends AdminBase
    {

        public function initialize()
        {
            parent::initialize(); // TODO: Change the autogenerated stub
        }


        /**
         * @throws \think\Exception
         * @throws \think\exception\PDOException
         * @author: LuckyHhy <jackhhy520@qq.com>
         * @date: 2020/3/26
         * @name: xiongzhang
         * @describe:
         */
        public function xiongzhang()
        {
            $action = $this->request->post("action");
            $urls = $this->request->post("urls");
            $urls = explode("\n", $urls);
            $urls = array_unique(array_filter($urls));
            if (!$urls) {
                $this->error("URL列表不能为空");
            }

            $result = false;
            if ($action == 'urls') {
                $type = $this->request->post("type");
                if ($type == 'realtime') {
                    $result = Push::init(['type' => 'xiongzhang'])->realtime($urls);
                } else {
                    $result = Push::init(['type' => 'xiongzhang'])->history($urls);
                }
            } elseif ($action == 'del') {
                $result = Push::init(['type' => 'xiongzhang'])->delete($urls);
            }

            if ($result) {
                $data = Push::init()->getData();
                $this->success("推送成功", null, $data);
            } else {
                $this->error("推送失败：" . Push::init()->getError());
            }
        }
    }